package com.reliable.api.dto.address;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Arrays;

/**
 * 国家信息响应DTO
 */
public class CountryInfo {

    private Name name;
    @JsonProperty("cca2")
    private String countryCode; // 如 CN
    @JsonProperty("cca3")
    private String countryCode3; // 如 CHN
    @JsonProperty("ccn3")
    private String countryCodeNumeric; // 如 156
    private double[] latlng; // [纬度, 经度]

    // Getters and Setters

    public static class Name {
        private String common;
        private String official;

        public String getCommon() { return common; }
        public void setCommon(String common) { this.common = common; }
        public String getOfficial() { return official; }
        public void setOfficial(String official) { this.official = official; }
    }

    public Name getName() { return name; }
    public void setName(Name name) { this.name = name; }

    public String getCountryCode() { return countryCode; }
    public void setCountryCode(String countryCode) { this.countryCode = countryCode; }

    public String getCountryCode3() { return countryCode3; }
    public void setCountryCode3(String countryCode3) { this.countryCode3 = countryCode3; }

    public String getCountryCodeNumeric() { return countryCodeNumeric; }
    public void setCountryCodeNumeric(String countryCodeNumeric) { this.countryCodeNumeric = countryCodeNumeric; }

    public double[] getLatlng() { return latlng; }
    public void setLatlng(double[] latlng) { this.latlng = latlng; }

    public Double getLatitude() {
        return latlng != null && latlng.length > 0 ? latlng[0] : null;
    }

    public Double getLongitude() {
        return latlng != null && latlng.length > 1 ? latlng[1] : null;
    }

    @Override
    public String toString() {
        return "CountryInfo{" +
                "name=" + (name != null ? name.common : "N/A") +
                ", countryCode='" + countryCode + '\'' +
                ", latlng=" + Arrays.toString(latlng) +
                '}';
    }
}